/**
 * Description: 阻塞IO写端
 * File:client_write |Time: 2021-07-19 21:12
 */


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

#define BUFSIZE 128

#define ERR(msg) do {   \
    perror(msg);    \
    printf("err_at: %s:%s %d\n", __FILE__, __func__, __LINE__); \
} while(0)



int main(int argc, const char *argv[])
{
    int ret;
    char buf[BUFSIZE] = {0};
    int fd = open("/dev/demo_dev", O_RDWR);
    if (fd < 0) 
    {
        ERR("open");
        return -1;
    }

    while (1)
    {
        printf("input to weak up read_client >>> ");
        fgets(buf, BUFSIZE, stdin);
        
        write(fd, buf, sizeof(buf));
        memset(buf, 0, sizeof(buf));
        printf("done.\n");
    }

    if (close(fd) < 0) 
    {
        ERR("close");
        return -1;
    }

    return 0;
}


